package com.sn.system.file.download;

import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletContext;

import com.sn.system.file.FileUtil;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CommonExportDataAction extends ActionSupport{

	private String fileName;
	
	private String downLoadPath;

	public InputStream getInputStream() throws Exception {   
		ServletContext sc = (ServletContext) ActionContext.getContext().get(ServletActionContext.SERVLET_CONTEXT);  
		String path = sc.getRealPath("/"); 
		
		InputStream stream = FileUtil.getDownloadFile(path+"Temp/DataExport/"+downLoadPath,null);        		
		File file = new File(path+"Temp/DataExport/"+downLoadPath);
		FileUtil.delFile(file);
		return stream;
    }   
	
	public String execute() throws Exception {   
		  
        return SUCCESS;   
  
    }   
 
  
    public void setFileName(String fileName) {   
      
        this.fileName = fileName;    
    }    
  
    public String getDownloadFileName() {   
  
        String downFileName = fileName;   
  
        try {   
  
            downFileName = new String(downFileName.getBytes("Windows-31J"),"ISO8859-1");   
  
        } catch (UnsupportedEncodingException e) {   
            e.printStackTrace();    
        }   
  
        return downFileName;   
  
    }

	public void setDownLoadPath(String downLoadPath) {
		this.downLoadPath = downLoadPath;
	}   
    
    
}
